// AddStationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Station.h"
#include "AddStationDlg.h"
#include "stationDlg.h"


// CAddStationDlg dialog

IMPLEMENT_DYNAMIC(CAddStationDlg, CDialog)

CAddStationDlg::CAddStationDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddStationDlg::IDD, pParent)
	, sname(_T(""))
	, sid(_T(""))
{

}

CAddStationDlg::~CAddStationDlg()
{
}

void CAddStationDlg::DoDataExchange(CDataExchange* pDX)
{
	DDX_Text( pDX,IDC_SNAME,sname);
	DDX_Text( pDX,IDC_SID,sid);
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLOT1, m_slot1);
	DDX_Control(pDX, IDC_SLOT2, m_slot2);
	DDX_Control(pDX, IDC_SLOT3, m_slot3);
	DDX_Control(pDX, IDC_SLOT4, m_slot4);
	DDX_Control(pDX, IDC_SLOT5, m_slot5);
	DDX_Control(pDX, IDC_SIPADDRESS, m_sip);
}


BEGIN_MESSAGE_MAP(CAddStationDlg, CDialog)
	ON_BN_CLICKED(IDOK, &CAddStationDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CAddStationDlg message handlers

void CAddStationDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	this->UpdateData();
	//sid must be set.
	if( sid.IsEmpty())
	{
		::AfxMessageBox("Station ID must be Set!");
		return ;
	}
	CstationDlg * pdlg = static_cast<CstationDlg*>(::AfxGetMainWnd());
	if( ! pdlg->checkID( sid ) )
	{
		::AfxMessageBox("Station ID has been used, please input another one!");
		return ;
	}
	//Only MM panel can be set.
	int nmmcount = 0 ;
	if( m_slot1.GetCurSel() == 2 )
	{
		nmmcount ++ ;
	}
	if( m_slot2.GetCurSel() == 2 )
	{
		nmmcount ++ ;
	}
	if( m_slot3.GetCurSel() == 2 )
	{
		nmmcount ++ ;
	}
	if( m_slot4.GetCurSel() == 2 )
	{
		nmmcount ++ ;
	}
	if( m_slot5.GetCurSel() == 2 )
	{
		nmmcount ++ ;
	}
	if ( nmmcount > 1 )
	{
		::AfxMessageBox("Only One MM panel Can be Set!");
		return ;
	}
	if( nmmcount == 0)
	{
		::AfxMessageBox("MM panel must be set!");
		return ;
	}
	//IP
	m_sip.GetAddress(dwSIP); 
		//panel info
	CString s;
	m_slot1.GetLBText((m_slot1.GetCurSel()),s);
	panel[0] = s[0];
	m_slot2.GetLBText((m_slot2.GetCurSel()),s);
	panel[1] = s[0];
	m_slot3.GetLBText((m_slot3.GetCurSel()),s);
	panel[2] = s[0];
	m_slot4.GetLBText((m_slot4.GetCurSel()),s);
	panel[3] = s[0];
	m_slot5.GetLBText((m_slot5.GetCurSel()),s);
	panel[4] = s[0];

	OnOK();
}

BOOL CAddStationDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here
	m_slot1.AddString("AA");  ///0
	m_slot1.AddString("BB");  ///1
	m_slot1.AddString("MM");  ///2
	m_slot1.AddString("No Set");
	m_slot1.SetCurSel(3);

	m_slot2.AddString("AA");
	m_slot2.AddString("BB");
	m_slot2.AddString("MM");
	m_slot2.AddString("No Set");
	m_slot2.SetCurSel(3);

	m_slot3.AddString("AA");
	m_slot3.AddString("BB");
	m_slot3.AddString("MM");
	m_slot3.AddString("No Set");
	m_slot3.SetCurSel(3);

	m_slot4.AddString("AA");
	m_slot4.AddString("BB");
	m_slot4.AddString("MM");
	m_slot4.AddString("No Set");
	m_slot4.SetCurSel(3);

	m_slot5.AddString("AA");
	m_slot5.AddString("BB");
	m_slot5.AddString("MM");
	m_slot5.AddString("No Set");
	m_slot5.SetCurSel(3);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
